package dannesNetworkTest;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

public class Client {

	private Socket socket;
	private OutputStream outputStream;
	private ObjectOutputStream objOut;
	private Boolean running = true;
	private Scanner reader = new Scanner(System.in);
	
	public static void main(String[] args) {
		Client client = new Client();
	}
	
	public Client() {
		try {
			socket = new Socket("130.237.223.115" , 1337);		//Create a socket
			System.out.println("Connection success");
			outputStream = socket.getOutputStream();		//create an outputstream
			objOut = new ObjectOutputStream(outputStream);	//create an objectoutputstream

			String message = null;
			while (running) {
				message = null;
				message = reader.nextLine();
				if(message != null) {
					if (message.equals("quit")) {			//Reads and sends a message
						running = false;
					}
					objOut.writeObject(message);
				}
				Thread.sleep(10);
			}
			
			objOut.close();									//Close the stream
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
